package panels;

import javax.swing.JPanel;
import javax.swing.JToolBar;
import java.awt.BorderLayout;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import java.awt.Dimension;
import javax.swing.JButton;

public class DataBrowserPanel extends JPanel {
	private JScrollPane scrollPane = null;
	public JTable table = null;
	private JToolBar toolBar = null;
	public JButton firstButton = null;
	public JButton addButton = null;
	public JButton deleteButton = null;
	public DataBrowserModel tableModel = null; // @jve:decl-index=0:visual-constraint=""
	private JButton lastButton = null;

	/**
	 * This is the default constructor
	 */
	public DataBrowserPanel() {
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setLayout(new BorderLayout()); // Generated
		this.setSize(300, 200);
		this.add(getToolBar(), java.awt.BorderLayout.NORTH); // Generated
		this.add(getScrollPane(), java.awt.BorderLayout.CENTER); // Generated
	}

	/**
	 * This method initializes scrollPane
	 * 
	 * @return javax.swing.JScrollPane
	 */
	private JScrollPane getScrollPane() {
		if (scrollPane == null) {
			scrollPane = new JScrollPane();
			scrollPane.setViewportView(getTable()); // Generated
		}
		return scrollPane;
	}

	/**
	 * This method initializes table
	 * 
	 * @return javax.swing.JTable
	 */
	private JTable getTable() {
		if (table == null) {
			table = new JTable();
			table.setDragEnabled(false);
			table.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF); // Generated
			table.setModel(getTableModel()); // Generated
		}
		return table;
	}

	/**
	 * This method initializes jToolBar
	 * 
	 * @return javax.swing.JToolBar
	 */
	private JToolBar getToolBar() {
		if (toolBar == null) {
			toolBar = new JToolBar();
			toolBar.setPreferredSize(new Dimension(133, 32)); // Generated
			toolBar.add(getFirstButton()); // Generated
			toolBar.add(getLastButton()); // Generated
			toolBar.add(new JToolBar.Separator(new Dimension(16, 16)));
			toolBar.add(getAddButton()); // Generated
			toolBar.add(getDeleteButton()); // Generated
		}
		return toolBar;
	}

	/**
	 * This method initializes jButton
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getFirstButton() {
		if (firstButton == null) {
			firstButton = new JButton();
			firstButton.setText("First"); // Generated
			firstButton.setMnemonic(java.awt.event.KeyEvent.VK_F); // Generated
		}
		return firstButton;
	}

	/**
	 * This method initializes jButton1
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getAddButton() {
		if (addButton == null) {
			addButton = new JButton();
			addButton.setText("Add"); // Generated
			addButton.setMnemonic(java.awt.event.KeyEvent.VK_A); // Generated
		}
		return addButton;
	}

	/**
	 * This method initializes jButton2
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getDeleteButton() {
		if (deleteButton == null) {
			deleteButton = new JButton();
			deleteButton.setText("Delete"); // Generated
			deleteButton.setMnemonic(java.awt.event.KeyEvent.VK_D); // Generated
		}
		return deleteButton;
	}

	/**
	 * This method initializes topicTableModel
	 * 
	 * @return table.DataBrowserModel
	 */
	private DataBrowserModel getTableModel() {
		if (tableModel == null) {
			tableModel = new DataBrowserModel();
		}
		return tableModel;
	}

	/**
	 * This method initializes jButton
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getLastButton() {
		if (lastButton == null) {
			lastButton = new JButton();
			lastButton.setMnemonic(java.awt.event.KeyEvent.VK_L); // Generated
			lastButton.setText("Last"); // Generated
		}
		return lastButton;
	}

	public void clear() {
		this.tableModel.clear();
	}

	public void enableAll() {
		this.firstButton.setEnabled(true);
		this.lastButton.setEnabled(true);
		this.addButton.setEnabled(true);
		this.deleteButton.setEnabled(true);
		this.table.setEnabled(true);
	}

	public void disableAll() {
		this.firstButton.setEnabled(false);
		this.lastButton.setEnabled(false);
		this.addButton.setEnabled(false);
		this.deleteButton.setEnabled(false);
		this.table.setEnabled(false);
	}
}
